/*通过网络等手段查找UML图的相关知识
（主要搜索UML表示类，和UML表示组合、依赖、继承、关联）。
根据下图编写代码，驯兽员如何让所有动物表演:*/
#include <iostream>
using namespace std;

class Animal
{
private:
    
public:
    Animal(){}
    ~Animal(){}
    virtual void showTime()=0;  //表演
};

class lion:public Animal
{
private:
    
public:
    lion(){}
    ~lion(){}
    void showTime()
    {
        cout<<"It's lion's showtime!"<<endl;
    }
};

class elephant:public Animal
{
private:
    
public:
    elephant(){}
    ~elephant(){}
    void showTime()
    {
        cout<<"It's elephant's showtime!"<<endl;
    }
};

class dolphin:public Animal
{
private:
    
public:
    dolphin(){}
    ~dolphin(){}
    void showTime()
    {
        cout<<"It's dolphin's showtime!"<<endl;
    }
};

class trainer
{
    //添加动物
    //删除动物
    //所有动物表演
private:
    Animal *lion1;
    Animal *elephant1;
    Animal *dolphin1;
public:
    trainer(){}
    ~trainer()
    {
        if(lion1 != 0)
        {
            delete(lion1);
        }
        if(elephant1 != 0)
        {
            delete(elephant1);
        }
        if(dolphin1 != 0)
        {
            delete(dolphin1);
        }
    }
    void addLion()
    {
        if(lion1 !=0)
        {
            cout<<"lion is live"<<endl;
        }
        else
        {
            lion1 = new lion;
        }
    }
    void addElephant()
    {
        if(elephant1 !=0)
        {
            cout<<"elephant is live"<<endl;
        }
        else
        {
            elephant1 = new elephant;
        }
    }
    void addDolphin()
    {
        if(dolphin1 !=0)
        {
            cout<<"dolphin is live"<<endl;
        }
        else
        {
            dolphin1 = new dolphin;
        }
    }
    void delLion()
    {
        if(lion1 == 0)
        {
            cout<<"have no lion"<<endl;
        }
        else
        {
            delete(lion1);
            lion1 = 0;
        }
    }
    void delElephant()
    {
        if(elephant1 == 0)
        {
            cout<<"have no elephant"<<endl;
        }
        else
        {
            delete(elephant1);
            elephant1 = 0;
        }
    }
    void delDolphin()
    {
        if(dolphin1 == 0)
        {
            cout<<"have no dolphin"<<endl;
        }
        else
        {
            delete(dolphin1);
            dolphin1 = 0;
        }
    }
    void showTimeNow()
    {
        int flag=0;
        if(lion1 != 0)
        {
            lion1->showTime();
            flag++;
        }
        if(elephant1 != 0)
        {
            elephant1->showTime();
            flag++;
        }
        if(dolphin1 != 0)
        {
            dolphin1->showTime();
            flag++;
        }
        if(flag == 0)
        {
            cout<<"have no animal!"<<endl;
        }
    }
};

int main(int argc,char*argv[])
{
    trainer *t1 = new trainer;
    t1->addLion();
    t1->addElephant();
    t1->addDolphin();
    t1->showTimeNow();

    cout<<endl;
    t1->delLion();
    t1->showTimeNow();
    return 0;
}